import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsNotEmpty, IsNumber, IsString, IsOptional, Min, IsEnum } from 'class-validator';
import { DiffDto } from 'src/common/dto/dto';
import { FreeState, Status } from 'src/dictionaries/index.enum';
import { FindOperator } from 'typeorm';

export class CreateMoviesEpisodeDto extends DiffDto {
    @ApiProperty({ description: '名称', example: '第一集' })
    @IsNotEmpty({ message: '名称不能为空' })
    @IsString()
    name: string;

    @ApiProperty({ description: '集编号', example: 1 })
    @IsNotEmpty({ message: '集编号不能为空' })
    @IsNumber()
    @Min(1, { message: '集编号必须大于等于1' })
    episodeNumber: number;

    @ApiPropertyOptional({ description: 'mp4链接', example: 'http://example.com/video.mp4' })
    @IsOptional()
    @IsString()
    mp4?: string;

    @ApiProperty({ description: '剧情图片', example: 'http://example.com/cover.jpg' })
    @IsNotEmpty({ message: '剧情图片不能为空' })
    @IsString()
    cover: string;

    @ApiProperty({ description: '金额', example: 9.99 })
    @IsNotEmpty({ message: '金额不能为空' })
    @IsNumber()
    @Min(0, { message: '金额不能小于0' })
    amount: number;

    @ApiProperty({ description: '电影ID', example: 1 })
    @IsNotEmpty({ message: '电影ID不能为空' })
    @IsNumber()
    movieId: number;

    @ApiProperty({ description: '点赞数', example: 1 })
    @IsNotEmpty({ message: '点赞数不能为空' })
    @IsNumber()
    @Min(0, { message: '点赞数必须大于等于0' })
    likeCount: number;

    @ApiProperty({ description: '播放量', example: 1 })
    @IsNotEmpty({ message: '播放量不能为空' })
    @IsNumber()
    @Min(0, { message: '播放量必须大于等于0' })
    playCount: number;

    @ApiProperty({ description: '收藏量', example: 1 })
    @IsNotEmpty({ message: '收藏量不能为空' })
    @IsNumber()
    @Min(0, { message: '收藏量必须大于等于0' })
    collectCount: number;

    /** 是否上架 */
    @IsEnum(Status)
    @IsNotEmpty({ message: '状态不能为空' })
    @ApiProperty({
        name: 'status',
        description: '是否上架',
        enum: Status,
    })
    public readonly status: Status;

    @ApiProperty({ description: '是否免费' })
    @IsEnum(FreeState)
    @IsNotEmpty()
    free: FreeState;  // 新增free字段，用于表示是否免费
}

export class UpdateMoviesEpisodeDto extends CreateMoviesEpisodeDto {
    @ApiProperty({ description: '集ID', example: 1 })
    @IsNotEmpty({ message: '集ID不能为空' })
    @IsNumber()
    id: number;
}

export class GetMoviesEpisodeDto {
    /** 标题 */
    @ApiPropertyOptional({
        type: String,
        name: 'name',
        description: '标题',
    })
    public readonly name?: FindOperator<string>;
    @ApiPropertyOptional({ description: '电影ID', example: 1 })
    movieId?: number;

    @ApiPropertyOptional({ description: '页码', example: 1 })
    pageNum?: number;

    @ApiPropertyOptional({ description: '每页条数', example: 10 })
    pageSize?: number;
}
